/*
 * @Author: sjf 1758142861@qq.com
 * @Date: 2023-03-23 17:27:21
 * @LastEditors: sjf 1758142861@qq.com
 * @LastEditTime: 2023-03-23 18:03:00
 * @FilePath: /sjf/lwp/posix_sem/test.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"ring_queue.hpp"
#include<cstdlib>
#include<time.h>

void* _producer(void* args)
{
    Anwtie::RingQueue<int>* queue = (Anwtie::RingQueue<int>*)(args);
    while(true)
    {
        sleep(1);
        int data = rand() % 1024;
        queue->push(data);
        std::cout << "_producer push one data->" << data << std::endl; 
    }
    return nullptr;
}

void* _consumer(void* args)
{
    Anwtie::RingQueue<int>* queue = (Anwtie::RingQueue<int>*)(args);
    while(true)
    {
        sleep(1);
        int data = 0;
        queue->pop(data);
        std::cout << "_consumer pop one data->" << data << std::endl;
    }
    return nullptr;
}

int main()
{
    srand((unsigned int)time(nullptr));
    pthread_t tid1,tid2;
    Anwtie::RingQueue<int>* queue = new Anwtie::RingQueue<int>;
    pthread_create(&tid1,nullptr,_producer,(void*)queue);
    pthread_create(&tid2,nullptr,_consumer,(void*)queue);

    pthread_join(tid1,nullptr);
    pthread_join(tid2,nullptr);

    delete queue;
    return 0;
}